import request from '@/api/request'
import { getAllTime } from '@/utils/timeTools.js'
export function meetingList(data) {
  return request({
    url: '/emrweb/meeting/user/meeting/list',
    method: 'GET',
    data,
  })
}

export function addMeeting(params) {
  if (params.type === 0) {
    params.startTime = getAllTime(params.times[0])
    params.endTime = getAllTime(params.times[1])
  }
  const tParams = {
    end_time: params.endTime,
    instanceid: 1,
    meeting_type: 0,
    password: params.password,
    settings: {
      mute_enable_join: params.isMute,
    },
    start_time: params.startTime,
    subject: params.name,
    type: params.type,
  }
  if (params.id) {
    return change({ ...tParams, id: params.id })
  }
  return request({
    url: '/emrweb/meeting/create',
    method: 'POST',
    data: tParams,
  })
}

export function find(data) {
  return request({
    url: '/emrweb/meeting/find/meeting_id',
    method: 'POST',
    data,
  })
}

export function close(data) {
  const { meeting_id } = data
  return request({
    url: `/emrweb/meeting/dismiss/${meeting_id}`,
    method: 'POST',
    data: {
      instanceid: 1,
      meeting_type: 0,
      reason_code: 0,
      reason_detail: '',
    },
  })
}

export function cancel(data) {
  const { meeting_id } = data
  return request({
    url: `/emrweb/meeting/cancel/${meeting_id}`,
    method: 'POST',
    data: {
      instanceid: 1,
      meeting_type: 0,
      reason_code: 0,
      reason_detail: '',
    },
  })
}

export function change(params) {
  const { id } = params
  return request({
    url: `/emrweb/meeting/modify/${id}`,
    method: 'put',
    data: params,
  })
}

export function loadAttList(params) {
  return request({
    url: `/emrweb/meeting/participants`,
    method: 'GET',
    params,
  })
}
